package com.exam.api.modules.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.api.common.dto.KeywordPageDTO;
import com.exam.api.common.web.TinyResponse;
import com.exam.api.modules.order.mapper.TblOrderMapper;
import com.exam.api.modules.order.service.OrderSyncDataService;
import com.exam.api.modules.order.service.TblOrderService;
import com.exam.api.modules.order.vo.OrderVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * (管理端) 订单相关接口
 */
@Tag(name = "(管理端) 订单相关接口", description = "(管理端) 订单相关接口")
@RestController
@RequestMapping("/manager/order")
@TinyResponse
public class TblOrderController {

    @Resource
    private TblOrderService tblOrderService;
    @Resource
    private TblOrderMapper orderMapper;
    @Resource
    private OrderSyncDataService orderSyncDataService;

    @Operation(summary = "通过班次id 查询学生列表", description = "创建订单")
    @PostMapping("/studentList/{classNumberId}")
    public List<OrderVO> studentList(@PathVariable("classNumberId") Long classNumberId) {
        return tblOrderService.studentList(classNumberId);
    }

    @Operation(summary = "分配班级", description = "更新座位")
    @PostMapping("/allocation/{classNumberId}")
    public void studentList(@PathVariable("classNumberId") Long classNumberId,@RequestBody List<Long> userIds) {
        tblOrderService.allocation(classNumberId,userIds);
    }

//    @Operation(summary = "创建订单", description = "创建订单")
//    @PostMapping("/create")
//    public void createTblOrder(@RequestBody TblOrder tblOrder) {
//        tblOrderService.save(tblOrder);
//    }
//
//    @Operation(summary = "修改订单", description = "修改订单")
//    @PostMapping("/update")
//    public void updateTblOrder(@RequestBody TblOrder tblOrder) {
//        tblOrderService.updateById(tblOrder);
//    }
//
    @Operation(summary = "分页查询订单", description = "分页查询订单")
    @PostMapping("/page")
    public IPage<OrderVO> pageTblOrder(@RequestBody KeywordPageDTO dto) {
        return orderMapper.selectOrderList(Page.of(dto.getPageNum(),dto.getPageSize()),dto);
    }

    @Operation(summary = "查询同步状态", description = "查询同步状态")
    @PostMapping("/syncStatus")
    public Boolean syncStatus() {
        return orderSyncDataService.syncStatus();
    }

    @Operation(summary = "同步订单", description = "同步订单")
    @PostMapping("/maulSyncOrder")
    public void maulSyncOrder() {
        orderSyncDataService.syncRefreshYzOrderList();
    }

//    @Operation(summary = "根据ID查询订单", description = "根据ID查询订单")
//    @GetMapping("/{id}")
//    public TblOrder getTblOrderById(@PathVariable("id") Long id) {
//        return tblOrderService.getById(id);
//    }
//
//    @Operation(summary = "删除订单", description = "删除订单")
//    @PostMapping("/delete/{id}")
//    public void deleteTblOrder(@PathVariable("id") Long id) {
//        tblOrderService.removeById(id);
//    }
}
